<?php 
Class Shipping_location_model extends CI_Model
{
	function __construct()
	{
		$this->_table = "";
	}
	public function get_ship_price_loacation($total_weight,$id_zone){
		// max chỉ giới han mõi don hàng
		if(!empty($total_weight) && !empty($id_zone)){
			$result = $this->db->select("ship_weight.value as value_weight,ship_cost.value price")->where("country_zones.id",$id_zone)->join("ship_cost","country_zones.ship_location_id = ship_cost.location_id")->join("ship_weight","ship_weight.id = ship_cost.weight_id")->where("ship_cost.weight_id <>",0)->where("ship_weight.value >=",$total_weight)->order_by("ship_weight.value","ASC")->get("country_zones")->row();
			if(empty($result)){
				$result = $this->db->select("ship_weight.value as value_weight,ship_cost.value price")->where("country_zones.id",$id_zone)->join("ship_cost","country_zones.ship_location_id = ship_cost.location_id")->where("ship_cost.weight_id <>",0)->join("ship_weight","ship_weight.id = ship_cost.weight_id")->order_by("ship_weight.value","DESC")->get("country_zones")->row();
			}
			return $result;
		}
	}
	public function get_shipping_price_config($id_zone){
		if(!empty($id_zone)){
			return $this->db->select("ship_cost.*,ship_weight.value as value_weight")->where("ship_cost.weight_id",0)->join("ship_cost","ship_weight.id = ship_cost.weight_id")->join("country_zones","country_zones.ship_location_id = ship_cost.location_id")->where("country_zones.id",$id_zone)->get("ship_weight")->row();	
		}		
	}
	public function get_result_max_weight(){
		return $this->db->select_max("value")->where("id <>",0)->get("ship_weight")->row();	
	}
	public function get_price_hcm_max_price($id_hcm){
		return $this->db->select_max("ship_cost.value")->where("country_zones.id",$id_hcm)->join("ship_cost","ship_cost.location_id = country_zones.ship_location_id")->get("country_zones")->row();
	}
}
?>